<%@ page language="java" pageEncoding="UTF-8"
	errorPage="../../defaultException.jsp"%>
<%@include file="../../tags.jsp"%>
<html>
<head>
<title>酒店信息管理</title>
<%@include file="../../head.jsp"%>


</head>
<body>
	<table id="list_data" cellspacing="0" cellpadding="0">
		<thead>
			<tr>
				<th field="review" formatter="renderReview">评论</th>
				<th field="operator" formatter="renderOperator">特色/图文</th>
				<th field="viewStyle" formatter="renderViewStyle">酒店版本</th>
				<th field="zhname">中文名</th>
				<th field="enname">英文名</th>
				<th field="email">邮箱</th>
				<th field="url">网址</th>
				<th field="address">地址</th>
				<th field="tel">电话</th>
				<th field="houses">房间数</th>
				<th field="price">最低价</th>
				<th field="score">总评分</th>
				<th field="lat">酒店纬度</th>
				<th field="lng">酒店经度</th>
				<th field="copyright">酒店版权</th>
				<th field="logo" formatter="formatCell">酒店logo</th>
				<th field="viewnum">酒店浏览次数</th>
				<th field="summary">酒店概述摘要</th>
			</tr>
		</thead>
	</table>

	<div id="addHotelResourceInfoDialog"
		style="width: 400px; height: 280px; padding: 10px 20px"></div>
<script type="text/javascript">
function formatCell(value, row, index) {
	return "<img src='${image_domain}"+value+"' width='150' height='100'>";
}
var viewStyle = {
		'1' : '完整版',
		'2' : '简化版'
}
function renderViewStyle(value, row, index){
	return viewStyle[value];
}
function renderOperator(value, row, index) {
	var viewStyle = row.viewStyle;
	if(viewStyle == 1){
		return "<a href='${cpath }/admin/hotel/resource/vlist?destId=${destId}&hotelId="
		+ row.hotelId + "'>特色管理</a>";
	}
	else
	{
		return "<a href='${cpath }/admin/hotel/text/vlist?hotelId="
		+ row.hotelId + "'>图文管理</a>";	
	}
	
}
function renderReview(value, row, index) {
	return "<a href='${cpath }/admin/hotel/review/vlist?hotelId="
			+ row.hotelId + "'>评论</a>";
}
</script>
	<script type="text/javascript">
		
		$('#list_data')
				.datagrid(
						{
							title : '<a href=${cpath }/admin/dest/vlist>目的地</a>&gt&gt<c:out value="${dest.zhname}" escapeXml="true" />',
							iconCls : 'icon-edit',//图标 
							width : 1024,
							height : 'auto',
							nowrap : false,
							striped : true,
							border : true,
							collapsible : false,//是否可折叠的 
							fitColumns : true,//自动大小 
							fit : true,
							url : '${cpath }/admin/hotel/list?destId=${dest.destId}',
							remoteSort : false,
							idField : 'hoteId',
							singleSelect : true,//是否单选 
							pagination : true,//分页控件 
							rownumbers : true,//行号 
							toolbar : [
									{
										text : '添加酒店',
										iconCls : 'icon-add',
										handler : function() {
											//openDialog("add_dialog","add");
											var saveAction = cpath
													+ '/admin/hotel/save?destId=${destId}';
											var openAction = cpath
													+ '/admin/hotel/vsave';
											openAddHotelBaseInfoDialog('添加酒店',
													openAction, saveAction,
													addHotelBaseInfoSuccess);
										}
									},
									'-',
									{
										text : '修改酒店',
										iconCls : 'icon-edit',
										handler : function() {
											//openDialog("add_dialog","add");
											var saveAction = cpath
													+ '/admin/hotel/update';
											var openAction = cpath
													+ '/admin/hotel/vupdate';
											openUpdateHotelBaseInfoDialog(
													'修改酒店', openAction,
													saveAction,
													addHotelBaseInfoSuccess,
													getSelectHotel);
										}
									},
									'-',
									{
										text : '删除酒店',
										iconCls : 'icon-edit',
										handler : function() {
											//openDialog("add_dialog","add");
											var deleteAction = cpath
													+ '/admin/hotel/delete';

											deleteHotelInfo(deleteAction,
													getSelectHotel);
										}
									},
									'-',
									{
										text : '修改酒店服务',
										iconCls : 'icon-edit',
										handler : function() {
											//openDialog("add_dialog","add");
											var saveAction = cpath
													+ '/admin/hotel/hotelservice/update';
											var openAction = cpath
													+ '/admin/hotel/hotelservice/vupdate';
											openAddHotelBaseInfoDialog(
													'修改酒店服务', openAction,
													saveAction,
													addHotelBaseInfoSuccess,
													getSelectHotel);
										}
									},
									'-',
									{
										text : '修改酒店风格',
										iconCls : 'icon-edit',
										handler : function() {
											//openDialog("add_dialog","add");
											var saveAction = cpath
													+ '/admin/hotel/hotelstyle/update';
											var openAction = cpath
													+ '/admin/hotel/hotelstyle/vupdate';
											openAddHotelBaseInfoDialog(
													'修改酒店风格', openAction,
													saveAction,
													addHotelBaseInfoSuccess,
													getSelectHotel);
										}
									},'-',{
										text : '刷新',
										iconCls : 'icon-reload',
										handler : function() {
											$('#list_data').datagrid('reload');
											save_status = false;
										}
									} ]
						});
		//设置分页控件 
		var p = $('#list_data').datagrid('getPager');
		$(p).pagination({
			pageSize : 10,//每页显示的记录条数，默认为10 
			pageList : [ 5, 10, 15 ],//可以设置每页记录条数的列表 
			beforePageText : '第',//页数文本框前显示的汉字 
			afterPageText : '页    共 {pages} 页',
			displayMsg : '当前显示 {from} - {to} 条记录   共 {total} 条记录'
		});
	</script>
	<script type="text/javascript">
		var url;
		var cpath = '${cpath}';
		function addHotelBaseInfoSuccess() {
			$('#list_data').datagrid('reload'); // reload the user data
		}
		function getSelectHotel() {
			return $('#list_data').datagrid('getSelected');
		}
		function openAddHotelBaseInfoDialog(dlgtitle, openAction, saveAction,
				successCallback, getSelectHotel) {
			if (getSelectHotel) {
				//添加信息，需要是否有前置条件
				if (getSelectHotel) {
					var row = getSelectHotel();
					//没有选中行，则需要提示
					if (!row) {
						$.messager.alert("提示", "请选择一个酒店", "info");
						return;
					} else {
						//选中了一行需在saveAction后加上目的地编号
						saveAction += '?hotelId=' + row.hotelId;
						openAction += '?hotelId=' + row.hotelId;
					}
				}
			}
			$('#addHotelResourceInfoDialog').dialog({
				title : dlgtitle,
				width : 800,
				height : 500,
				closed : false,
				cache : false,
				resizable : true,
				href : openAction,
				modal : true,
				closed : true,
				buttons : [ {
					text : '保存',
					iconCls : "icon-ok",
					handler : function() {
						saveHotelBaseInfoForm(saveAction, successCallback);
					}
				}, {
					text : '取消',
					iconCls : "icon-cancel",
					handler : function() {
						$('#addHotelResourceInfoDialog').dialog('close');
					}
				} ]
			});
			$('#addHotelResourceInfoDialog').dialog('open');
		}

		function openUpdateHotelBaseInfoDialog(dlgtitle, openAction,
				saveAction, successCallback, getSelectHotel) {
			//添加信息，需要是否有前置条件
			if (getSelectHotel) {
				var row = getSelectHotel();
				//没有选中行，则需要提示
				if (!row) {
					$.messager.alert("提示", "请选择一个酒店", "info");
					return;
				} else {
					//选中了一行需在saveAction后加上目的地编号
					saveAction += '?hotelId=' + row.hotelId;
					openAction += '?hotelId=' + row.hotelId;
					//var queryHotelIsUpdateAction = cpath + '/admin/hotel/hotelAction.do?action=queryHotelIsHome';

					$('#addHotelResourceInfoDialog').dialog({
										title : dlgtitle,
										width : 800,
										height : 500,
										closed : false,
										cache : false,
										resizable : true,
										href : openAction,
										modal : true,
										closed : true,
										buttons : [{
													text : '保存',
													iconCls : "icon-ok",
													handler : function() {
														saveHotelBaseInfoForm(
																saveAction,
																successCallback);
													}
												},
												{
													text : '取消',
													iconCls : "icon-cancel",
													handler : function() {
														$('#addHotelResourceInfoDialog').dialog('close');
														$('#list_data').datagrid('clearSelections');
													}
												} ]
									});
					$('#addHotelResourceInfoDialog').dialog('open');
					$('#list_data').datagrid('clearSelections');
				}
			}
		}
		var save_status = false;

		function saveHotelBaseInfoForm(saveAction, successCallback) {
			if (save_status) {
				$.messager.alert("提示", "请耐心等待。。。后台执行中。。。", "info");
				return;
			}
			save_status = true;
			$('#fm').form('submit', {
				url : saveAction,
				onSubmit : function() {
					var result =  $(this).form('validate');
					if (!result){
						save_status = false;
					}
					return result;
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.resultCode !== '00000000') {
						$.messager.alert("错误", result.resultMsg, "error");
						$('#list_data').datagrid('clearSelections');
					} else {
						$.messager.alert("成功", result.resultMsg, "info");
						$('#addHotelResourceInfoDialog').dialog('close');
						if (successCallback) {
							successCallback();
						}
						$('#list_data').datagrid('clearSelections');
					}
					save_status = false;
				}
			});
		}

		function deleteHotelInfo(deleteAction, getSelectHotel) {
			//添加信息，需要是否有前置条件
			if (getSelectHotel) {

				var row = getSelectHotel();
				//没有选中行，则需要提示
				if (!row) {
					$.messager.alert("提示", "请选择要删除的酒店！", "info");
					return;
				}
				if (row) {
					$.messager.confirm("提示", "确认要删除酒店吗？", function(r) {
						if (r) {
							$.post(deleteAction, row,
									function(result) {
										if (result.resultCode === '00000000') {
											$('#list_data').datagrid('reload'); // reload the user data
											$.messager.alert("提示",
													result.resultMsg, "info");
											$('#list_data').datagrid(
													'clearSelections');
										} else {
											$.messager.alert("错误",
													result.resultMsg, "error");
											$('#list_data').datagrid(
													'clearSelections');
										}
									}, 'json');
						}
					});
				}
			}
		}
	</script>
</body>
</html>